#include<string>
#include<vector>
#include<climits>
#include<iostream>
class Bitset {
    
public:
    std::vector<int> store;
    bool isflip = false;
    int ssize = 0;
    int ones = 0;
    int zeros = 0;
    Bitset(int size) {
        ssize = size;
        int intsize = (size + 32 - 1) / 32;
        ones = 0;
        zeros = size;
        store.resize(intsize);
    }

    void fix(int idx) {
        int index = idx / 32;
        int intindex = idx % 32;
        if (isflip) {
            int now = store[index];
            store[index] &= ~(1 << intindex);
            if (now != store[index]) {
                zeros--;
                ones++;
            }
        }
        else {
            int now = store[index];
            store[index] |= (1 << intindex);
            if (now != store[index]) {
                zeros--;
                ones++;
            }
        }
        std::cout << store[index]<<" " << zeros <<" " << ones << std::endl;
     
    }

    void unfix(int idx) {
        int index = idx / 32;
        int intindex = idx % 32;
        if (isflip) {
            int now = store[index];
            store[index] |= (1 << intindex);
            if (now != store[index]) {
                zeros++;
                ones--;
            }
        }
        else {
           
            int now = store[index];
            store[index] &= ~(1 << intindex);
            if (now != store[index]) {
                zeros++;
                ones--;
            }
        }
        std::cout << store[index] << " " << zeros << " " << ones << std::endl;

    }

    void flip() {
        isflip = !isflip;
        int on = ones;
        ones = zeros;
        zeros = on;
        std::cout << " " << zeros << " " << ones << std::endl;
    }

    bool all() {
        return ones == ssize;
    }

    bool one() {
        return ones > 0;
    }

    int count() {

        return ones;
       
    }

    std::string toString() {
        int len = 0;
        std::string res = "";
        for (int i = 0; i < store.size(); i++) {
            for (int j = 0; j < 32; j++) {
                if (((store[i] & (1 << j)) == 0)!=isflip) {
                    res += '0';
                }
                else
                    res += '1';
                len++;
              
                if (len == ssize) {
                    return res;
                }
            }
        }
        return res;
    }
};

